<?php

class User_Model_DbTable_AclPermission extends Custom_Db_Table_Abstract
{

    public $_name = 'vt_acl_permissions';

	/**
	 * Get permissions by resource id
	 * @param int $resourceId
	 * @return array available and assigned permissions
	 */
	public function getPermissions($resourceId, $totalPermissions)
	{
		$rows = $this->getByColumn('resource_id', $resourceId);
		$permissions = array();

		if($rows)
		{
			$temp_assigend = array();

			foreach($rows as $row)
			{
				$permissions['assigned'][] = $row;
				$temp_assigend[] = $row['permission'];
			}
			$permissions['available'] = array_values(array_diff($totalPermissions, $temp_assigend));
		}
		else
		{
			$permissions['available']= $totalPermissions;
			$permissions['assigned'] = array();
		}

		return $permissions;
	}

}

